﻿using System;
using System.Linq;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.DataLayer.Infra;

namespace ProjetoComperio.BusinessLogicLayer
{
    public class CommentBLL : ComperioDataObject
    {
        /// <summary>
        /// This method creates a new comment in db
        /// </summary>
        /// <param name="comment"></param>
        public void Create(Comment comment)
        {
            DbContext.Comments.Add(comment);
            DbContext.SaveChanges();
        }

        /// <summary>
        /// This method returns a specific comment from db
        /// </summary>
        /// <param name="commentId"></param>
        /// <returns></returns>
        public Comment RetrieveComment(Int32 commentId)
        {
            return DbContext.Comments.Where(comment => comment.CommentID == commentId).SingleOrDefault();
        }

        /// <summary>
        /// This method returns comments from by specific subject from db
        /// </summary>
        /// <param name="subjectId"></param>
        /// <returns></returns>
        public IQueryable<Comment> RetrieveComments(Int32 subjectId)
        {
            return DbContext.Comments.Where(comment => comment.SubjectId == subjectId);
        }
    }
}
